import Schema from 'async-validator';

export default class Validator {
  private validator: Schema
  constructor(rules) {
    this.validator = new Schema(rules)
  }
  validate(from) {
    return new Promise((resolve) => {
      this.validator.validate(from, (errors) => {
        resolve(errors)
      })
    })
  }
}

export const validFormItem = (rules, from) => {
  const validator = new Validator(rules)
  return validator.validate(from)
}
